package nl.fonfolio.view.avatar {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import nl.fonfolio.model.Model;
	import nl.fonfolio.controller.Controller;
	
	import flash.display.Sprite;
	
	import nl.fonfolio.core.Fonfolio;	

	/**
	 * @author Piels
	 */
	public class Avatar extends MovieClip {
		public var head:Head;
		public var body:MovieClip;
		private var fonfolio:Fonfolio;
		private var model : Model;
		private var controller : Controller;
		private var settings : Object;
		public var opened:Boolean;

		public function Avatar(fonfolio : Fonfolio,model : Model,controller : Controller, settings:Object) {
			this.settings = settings;
			this.controller = controller;
			this.model = model;
			this.fonfolio = fonfolio;
			this.addEventListener(MouseEvent.ROLL_OVER, onMouseOver);
			this.addEventListener(MouseEvent.ROLL_OUT, onMouseOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN, onClick, true,0,false);
			
			
			
			init(settings);
		}
		
		private function onClick(event : MouseEvent) : void {
			trace ("AVATAR: Avatar "+ settings.userId +" clicked");
			this.fonfolio.openProfile(settings.userId);
		}
		

		private function onMouseOut(event:MouseEvent):void {
			this.head.shrink();
		}

		private function onMouseOver(event:MouseEvent):void {
			this.head.grow();
		}

		private function init(settings:Object) : void {
			//this.head.mouth.setClip(settings.mouth.image);
			//this.head.nose.setClip(settings.nose.image);
			this.head.eyeLeft.setClip(settings.avatar.eye.image);
			this.head.eyeRight.setClip(settings.avatar.eye.image);
		}
	}
}
